/*
CREATE AN ASSISTING DATASET WITH DATE OF BIRTH

Data 	: DS_Lev_LISAind2000.dta to DS_Lev_LISAind2013.dta 
Folder 	: rawdata/dtafiles/DS_Lev_LISAind20**.dta
Date	: 2016-12-06

Creator		: Jonas Cederlof (JC)
Description : 	Creating an assisting dataset with date of birth for indiviuals 
		all indivuals in LISA from 2000 to 2013. This is to be merged onto
		the varseldata on indiviuals in order to determine their age at 
		the time of displacement. Merged onto varseldata in 
		A2_merge_firm_person.do
			  
	
Notes		 	: 
LATEST UPDATE 	: 2017-01-26
*/

********************************************************************************

clear
set more		off
cap   log close 	_all

log using 	"../log/A0_fodelsedatum.log", replace 



{ // Getting month of birth
*===============================================================================			
use 	lopnr fodelsemanad	using "$rawdatapath/lisa_ind_2000.dta" , clear

*Appending LISA 2001 to 2013
forvalues i=2001(1)2013	{
	append using "$rawdatapath/lisa_ind_`i'.dta", keep(lopnr fodelsemanad)
}	

*Drop duplicates
gduplicates drop lopnr, force
destring fodelsemanad, replace
}
*
{ // Merge month and year of birth
*===============================================================================
merge 1:1 lopnr  	using "$rawdatapath/yearofbirth.dta"
keep if _merge==3
drop 	_merge
}
*

*Generate: Year and month of birth
gen 		birth = ym(fodelsear, fodelsemanad)
format  	birth %tm

*Rename ID-variable
rename lopnr persid

*Dropping redundant variabels
drop  fodelsear fodelsemanad

*Save
compress
save "$datapath/A0_fodelsedatum.dta", replace


log close

